# koroFileHeader at Yungoal acer
# Create: 2021-04-25 17:19:17
# LastEdit: 2021-04-26 10:27:41
"""说明暂无"""
__author__ = '749B'


import unittest

if __name__ == '__main__':
    import os
    import sys
    sys.path.append(os.getcwd())
# pylint: disable = import-error
from azure_client.data_format import parse_time


class ParseTimeTestCase(unittest.TestCase):

    def test_parse_time(self):
        befor = []
        after = []
        # 时间为空字符串。不处理
        befor.append({'name': "Node1", 'Point': '', 'BackupTime': ''})
        after.append({'name': "Node1", 'Point': '', 'BackupTime': ''})
        # 零点的时间
        befor.append({'name': "server2", 'Point': '', 'BackupTime': '2001-01-01T00:00:00.0000000Z'})
        after.append({'name': "server2", 'Point': '', 'BackupTime': '2001-01-01T08:00:00Z+0800'})        
        # 比较早的一个时间
        befor.append({'name': "DB3", 'Point': '2018-10-23T07:40:12.9826881Z', 'BackupTime': '2018-10-23T07:40:59.7467556Z'})
        after.append({'name': "DB3", 'Point': '2018-10-23T15:40:12Z+0800', 'BackupTime': '2018-10-23T15:40:59Z+0800'})        
        # 比较近的一个时间
        befor.append({'name': "node4", 'Point': '2021-04-25T08:05:24.5290000Z', 'BackupTime': '2021-04-25T08:04:34.4660000Z'})
        after.append({'name': "node4", 'Point': '2021-04-25T16:05:24Z+0800', 'BackupTime': '2021-04-25T16:04:34Z+0800'})
        # 跨天的时间
        befor.append({'name': "node5", 'Point': '2021-04-25T18:00:52.0620000Z', 'BackupTime': '2021-04-25T18:00:48.6890000Z'})
        after.append({'name': "node5", 'Point': '2021-04-26T02:00:52Z+0800', 'BackupTime': '2021-04-26T02:00:48Z+0800'})
        # 数字，不当时间戳处理，平台没有转时间戳。不处理
        befor.append({'name': "node5", 'Point': 278616032, 'BackupTime': '244886032'})
        after.append({'name': "node5", 'Point': 278616032, 'BackupTime': '244886032'})
        # todatetime，平台有提供这个格式化方法
        befor.append({'name': "node5", 'Point': '2021-04-25T18:00:52.062Z', 'BackupTime': '2021-04-25T18:00:48.689Z'})
        after.append({'name': "node5", 'Point': '2021-04-26T02:00:52Z+0800', 'BackupTime': '2021-04-26T02:00:48Z+0800'})
        
        parse_time(befor)
        self.assertEqual(befor, after)


if __name__ == '__main__':
    unittest.main()
